#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1010;
int n,m,head[MAXN],cnt,depth[MAXN],f[20][MAXN],dis[20][MAXN];
struct edge
{
	int v,next,val;
}e[MAXN*2];
void addedge(int x,int y,int z)
{
	e[++cnt]=(edge){y,head[x],z};
	head[x]=cnt;
	return;
}
void dfs(int u)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(v==f[0][u])continue;
		depth[v]=depth[u]+1;
		f[0][v]=u;
		dis[0][v]=e[i].val;
		dfs(v);
	}
	return;
}
int LCA(int u,int v)
{
	int ret=0;
	if(depth[u]>depth[v])swap(u,v);
	for(int i=19;~i;--i)
		if(depth[f[i][v]]>=depth[u])
			ret+=dis[i][v],v=f[i][v];
	if(u==v)return ret;
	for(int i=19;~i;--i)
		if(f[i][u]!=f[i][v])
		{
			ret+=dis[i][u]+dis[i][v];
			u=f[i][u];
			v=f[i][v];
		}
	return ret+=dis[0][u]+dis[0][v];
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	for(int i=1;i<n;++i)
	{
		int x=read(),y=read(),z=read();
		addedge(x,y,z);addedge(y,x,z);
	}
	f[0][1]=1;
	dfs(1);
	for(int i=1;i<=19;++i)
		for(int j=1;j<=n;++j)
			f[i][j]=f[i-1][f[i-1][j]],dis[i][j]=dis[i-1][j]+dis[i-1][f[i-1][j]];
	while(m--)
	{
		int x=read(),y=read();
		printf("%d\n",LCA(x,y));
	}
	return 0;
}
